<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-10-20 09:25:00
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\MpcInventory;
use App\Models\MpcInventoryDetail;

class MpcInventoryRepository extends Repositories
    {

    protected $relation_models = ['creator', 'fauditor', 'updator', 'deletor', 'status', 'attachments', 'details' => ["material", "location"]];
    public function boot(MpcInventory $model)
        {
        $this->model = $model;
        }
    public function save($data, $withSort = false)
        {
        $data['details'] = collect($data->details)->map(function ($v)
            {
            $v['auxiliary_quantity'] = (float) $v['fect_auxiliary_quantity'] - (float) $v['storage_auxiliary_quantity'];
            $v['quantity'] = (float) $v['fect_quantity'] - (float) $v['storage_quantity'];
            return $v;
            });

        return parent::save($data, $withSort);
        }
    }